import java.lang.reflect.Array;
import java.util.Arrays;

public class 数组的三种创建方法 {
    public static void change(int[] arr) {
        arr[0] = 666;
    }
    public static int[] changeArr(int[] arr) {
        for (int i = 0; i < arr.length; i++) {
            arr[i]+=1000;
        }
        return arr;
    }
    public static void main(String[] args) {
        //创建数组
        int[] arr = {1,2,3,4};
        int[] arr1 = new int[]{1,2,3,4,5};
        int n = 3;
        int[] arr2 = new int[n];
        arr2 = new int[]{1,2,3};
        //遍历数组
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i] +" ");
        }
        System.out.println();
        for(int x:arr) {
            System.out.print(x+" ");
        }
        System.out.println();
        //数组传参
        change(arr);
        for(int x:arr) {
            System.out.print(x+" ");
        }
        System.out.println();
        //返回值类型是数组
        int[] a = {1,2,3,4,5,6,7,8};
        changeArr(a);
        for(int x:a) {
            System.out.print(x+" ");
        }
        int[] b = {123,21,12,5,131,346457,31315,65745,1};
        Arrays.sort(b);
        System.out.println();
        for(int x:b) {
            System.out.print(x+" ");
        }
        //转换为字符串打印
        System.out.println(Arrays.toString(b));

    }
}
